<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="想要把一个复杂的微服务项目部署到 K8S 上去，首先我们得学会把单个 SpringBoot 应用部署上去。今天我们来讲下如何把 SpringBoot 应用部署到 K8S 上去，和使用 Docker Compose 部署非常类似，希望对大家有所帮助！  #学前准备 学习本文需要有一些K8S基础，对K8S还不了解的朋友可以参考如下的文章。   《K8S太火了！花10分钟玩转它不香么？》 《自从上了K">
<meta property="og:type" content="article">
<meta property="og:title" content="我把SpringBoot应用部署到了K8S上，怎么感觉用起来像Docker！">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/c12cbbe61417.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="想要把一个复杂的微服务项目部署到 K8S 上去，首先我们得学会把单个 SpringBoot 应用部署上去。今天我们来讲下如何把 SpringBoot 应用部署到 K8S 上去，和使用 Docker Compose 部署非常类似，希望对大家有所帮助！  #学前准备 学习本文需要有一些K8S基础，对K8S还不了解的朋友可以参考如下的文章。   《K8S太火了！花10分钟玩转它不香么？》 《自从上了K">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:20:17.000Z">
<meta property="article:modified_time" content="2024-02-03T02:44:49.425Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/c12cbbe61417.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-03 10:44:49'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">我把SpringBoot应用部署到了K8S上，怎么感觉用起来像Docker！</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:20:17.000Z" title="发表于 2024-01-21 17:20:17">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-03T02:44:49.425Z" title="更新于 2024-02-03 10:44:49">2024-02-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/k8s/">k8s</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.9k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>8分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="我把SpringBoot应用部署到了K8S上，怎么感觉用起来像Docker！"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>想要把一个复杂的微服务项目部署到 K8S 上去，首先我们得学会把单个 SpringBoot 应用部署上去。今天我们来讲下如何把 SpringBoot 应用部署到 K8S 上去，和使用 Docker Compose 部署非常类似，希望对大家有所帮助！</p>
</blockquote>
<h2 id="学前准备"><a href="#学前准备" class="headerlink" title="#学前准备"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E5%AD%A6%E5%89%8D%E5%87%86%E5%A4%87">#</a>学前准备</h2><blockquote>
<p>学习本文需要有一些K8S基础，对K8S还不了解的朋友可以参考如下的文章。</p>
</blockquote>
<ul>
<li><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_start.html">《K8S太火了！花10分钟玩转它不香么？》</a></li>
<li><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_advance_start.html">《自从上了K8S，项目更新都不带停机的！》</a></li>
</ul>
<h2 id="推送镜像到Docker-Hub"><a href="#推送镜像到Docker-Hub" class="headerlink" title="#推送镜像到Docker Hub"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E6%8E%A8%E9%80%81%E9%95%9C%E5%83%8F%E5%88%B0docker-hub">#</a>推送镜像到Docker Hub</h2><blockquote>
<p>之前我们都是自建的镜像仓库，这次我们换种方式，把镜像上传到Docker Hub中去。</p>
</blockquote>
<ul>
<li>首先我们得注册个Docker Hub的账号，Docker Hub地址：<a target="_blank" rel="noopener" href="https://hub.docker.com/">https://hub.docker.com/</a></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-03_10:44:42_f3ccb4e85cc6032d3c40905ae2bf3b61.png"></p>
<ul>
<li>部署应用使用之前的<code>mall-tiny-fabric</code>项目，先修改<code>pom.xml</code>文件，主要是添加Docker Hub的认证信息和修改下镜像前缀，具体内容如下；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&lt;configuration&gt;</span><br><span class="line">    &lt;!-- Docker 远程管理地址--&gt;</span><br><span class="line">    &lt;dockerHost&gt;http://192.168.5.94:2375&lt;/dockerHost&gt;</span><br><span class="line">    &lt;!-- 添加认证信息--&gt;</span><br><span class="line">    &lt;authConfig&gt;</span><br><span class="line">        &lt;push&gt;</span><br><span class="line">            &lt;!--Docker Hub 用户名--&gt;</span><br><span class="line">            &lt;username&gt;macrodocker&lt;/username&gt;</span><br><span class="line">            &lt;!--Docker Hub 密码--&gt;</span><br><span class="line">            &lt;password&gt;xxx&lt;/password&gt;</span><br><span class="line">        &lt;/push&gt;</span><br><span class="line">    &lt;/authConfig&gt;</span><br><span class="line">    &lt;images&gt;</span><br><span class="line">        &lt;image&gt;</span><br><span class="line">            &lt;!--修改镜像前缀为Docker Hub 用户名--&gt;</span><br><span class="line">            &lt;name&gt;macrodocker/$&#123;project.name&#125;:$&#123;project.version&#125;&lt;/name&gt;</span><br><span class="line">        &lt;/image&gt;</span><br><span class="line">     &lt;/images&gt;</span><br><span class="line"> &lt;/configuration&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>修改完成后使用<code>package</code>命令先把镜像打包到Linux服务器，再使用<code>docker:push</code>命令把镜像推送到Docker Hub中去：</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-03_10:44:42_fff2b9bac38559d261114fb1cdaa31c6.png"></p>
<ul>
<li>推送成功以后就可以在Docker Hub中看到镜像了。</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-03_10:44:42_d345f6c645e51d46b0dfe84e8f2269ba.png"></p>
<h2 id="应用部署"><a href="#应用部署" class="headerlink" title="#应用部署"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E5%BA%94%E7%94%A8%E9%83%A8%E7%BD%B2">#</a>应用部署</h2><blockquote>
<p>接下来我们将把应用部署到K8S上去，包含SpringBoot应用的部署和MySQL的部署。</p>
</blockquote>
<h3 id="部署MySQL"><a href="#部署MySQL" class="headerlink" title="#部署MySQL"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E9%83%A8%E7%BD%B2mysql">#</a>部署MySQL</h3><ul>
<li>首先添加配置文件<code>mysql-deployment.yaml</code>用于创建Deployment，具体说明参考注释即可；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line">apiVersion: apps/v1</span><br><span class="line">kind: Deployment</span><br><span class="line">metadata:</span><br><span class="line">  # 指定Deployment的名称</span><br><span class="line">  name: mysql-deployment</span><br><span class="line">  # 指定Deployment的标签 </span><br><span class="line">  labels:</span><br><span class="line">    app: mysql</span><br><span class="line">spec:</span><br><span class="line">  # 指定创建的Pod副本数量 </span><br><span class="line">  replicas: 1</span><br><span class="line">  # 定义如何查找要管理的Pod</span><br><span class="line">  selector:</span><br><span class="line">    # 管理标签app为mysql的Pod</span><br><span class="line">    matchLabels:</span><br><span class="line">      app: mysql</span><br><span class="line">  # 指定创建Pod的模板</span><br><span class="line">  template:</span><br><span class="line">    metadata:</span><br><span class="line">      # 给Pod打上app:mysql标签</span><br><span class="line">      labels:</span><br><span class="line">        app: mysql</span><br><span class="line">    # Pod的模板规约</span><br><span class="line">    spec:</span><br><span class="line">      containers:</span><br><span class="line">        - name: mysql</span><br><span class="line">          # 指定容器镜像</span><br><span class="line">          image: mysql:5.7</span><br><span class="line">          # 指定开放的端口</span><br><span class="line">          ports:</span><br><span class="line">            - containerPort: 3306</span><br><span class="line">          # 设置环境变量</span><br><span class="line">          env:</span><br><span class="line">            - name: MYSQL_ROOT_PASSWORD</span><br><span class="line">              value: root</span><br><span class="line">          # 使用存储卷</span><br><span class="line">          volumeMounts:</span><br><span class="line">            # 将存储卷挂载到容器内部路径</span><br><span class="line">            - mountPath: /var/log/mysql</span><br><span class="line">              name: log-volume</span><br><span class="line">            - mountPath: /var/lib/mysql</span><br><span class="line">              name: data-volume</span><br><span class="line">            - mountPath: /etc/mysql</span><br><span class="line">              name: conf-volume</span><br><span class="line">      # 定义存储卷</span><br><span class="line">      volumes:</span><br><span class="line">        - name: log-volume</span><br><span class="line">          # hostPath类型存储卷在宿主机上的路径</span><br><span class="line">          hostPath:</span><br><span class="line">            path: /home/docker/mydata/mysql/log</span><br><span class="line">            # 当目录不存在时创建</span><br><span class="line">            type: DirectoryOrCreate</span><br><span class="line">        - name: data-volume</span><br><span class="line">          hostPath:</span><br><span class="line">            path: /home/docker/mydata/mysql/data</span><br><span class="line">            type: DirectoryOrCreate</span><br><span class="line">        - name: conf-volume</span><br><span class="line">          hostPath:</span><br><span class="line">            path: /home/docker/mydata/mysql/conf</span><br><span class="line">            type: DirectoryOrCreate</span><br></pre></td></tr></table></figure>

<ul>
<li>通过应用配置文件来创建Deployment；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl apply -f mysql-deployment.yaml</span><br></pre></td></tr></table></figure>

<ul>
<li>运行成功后查询Deployment，发现<code>mysql-deployment</code>已经就绪；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[macro@linux-local k8s]$ kubectl get deployments</span><br><span class="line">NAME                      READY   UP-TO-DATE   AVAILABLE   AGE</span><br><span class="line">mysql-deployment          1/1     1            1           38s</span><br><span class="line">nginx-volume-deployment   2/2     2            2           6d5h</span><br></pre></td></tr></table></figure>

<ul>
<li>想要其他Pod可以通过服务名称访问MySQL，需要创建Service，添加配置文件<code>mysql-service.yaml</code>用于创建Service；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">apiVersion: v1</span><br><span class="line">kind: Service</span><br><span class="line">metadata:</span><br><span class="line">  # 定义服务名称，其他Pod可以通过服务名称作为域名进行访问</span><br><span class="line">  name: mysql-service</span><br><span class="line">spec:</span><br><span class="line">  # 指定服务类型，通过Node上的静态端口暴露服务</span><br><span class="line">  type: NodePort</span><br><span class="line">  # 管理标签app为mysql的Pod</span><br><span class="line">  selector:</span><br><span class="line">    app: mysql</span><br><span class="line">  ports:</span><br><span class="line">    - name: http</span><br><span class="line">      protocol: TCP</span><br><span class="line">      port: 3306</span><br><span class="line">      targetPort: 3306</span><br><span class="line">      # Node上的静态端口</span><br><span class="line">      nodePort: 30306</span><br></pre></td></tr></table></figure>

<ul>
<li>通过应用配置文件来创建Service；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl apply -f mysql-service.yaml </span><br></pre></td></tr></table></figure>

<ul>
<li>运行成功后查询Service，发现<code>mysql-service</code>已经暴露在Node的<code>30306</code>端口上了；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[macro@linux-local k8s]$ kubectl get services</span><br><span class="line">NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE</span><br><span class="line">kubernetes      ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          7d23h</span><br><span class="line">mysql-service   NodePort    10.107.189.51    &lt;none&gt;        3306:30306/TCP   7s</span><br><span class="line">nginx-service   NodePort    10.101.171.181   &lt;none&gt;        80:30080/TCP     6d2h</span><br></pre></td></tr></table></figure>

<ul>
<li><p>部署完成后需要新建<code>mall</code>数据库，并导入相关表，表地址：<a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-learning/blob/master/document/sql/mall.sql">https://github.com/macrozheng/mall-learning/blob/master/document/sql/mall.sql</a></p>
</li>
<li><p>这里有个比较简单的方法来导入数据库，通过Navicat创建连接，先配置一个SSH通道；</p>
</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-03_10:44:42_a14e5da464d10e88f045a9162bc2310c.png"></p>
<ul>
<li>之后我们就可以像在Linux服务器上访问数据库一样访问Minikube中的数据库了，直接添加Minikube中数据库IP和端口即可。</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-03_10:44:42_98bbe81d504c88bec56253c6fd088435.png"></p>
<h3 id="部署SpringBoot应用"><a href="#部署SpringBoot应用" class="headerlink" title="#部署SpringBoot应用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E9%83%A8%E7%BD%B2springboot%E5%BA%94%E7%94%A8">#</a>部署SpringBoot应用</h3><ul>
<li>首先添加配置文件<code>mall-tiny-fabric-deployment.yaml</code>用于创建Deployment，这里我们可以通过环境变量来覆盖SpringBoot中的默认配置；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">apiVersion: apps/v1</span><br><span class="line">kind: Deployment</span><br><span class="line">metadata:</span><br><span class="line">  name: mall-tiny-fabric-deployment</span><br><span class="line">  labels:</span><br><span class="line">    app: mall-tiny-fabric</span><br><span class="line">spec:</span><br><span class="line">  replicas: 1</span><br><span class="line">  selector:</span><br><span class="line">    matchLabels:</span><br><span class="line">      app: mall-tiny-fabric</span><br><span class="line">  template:</span><br><span class="line">    metadata:</span><br><span class="line">      labels:</span><br><span class="line">        app: mall-tiny-fabric</span><br><span class="line">    spec:</span><br><span class="line">      containers:</span><br><span class="line">        - name: mall-tiny-fabric</span><br><span class="line">          # 指定Docker Hub中的镜像地址</span><br><span class="line">          image: macrodocker/mall-tiny-fabric:0.0.1-SNAPSHOT</span><br><span class="line">          ports:</span><br><span class="line">            - containerPort: 8080</span><br><span class="line">          env:</span><br><span class="line">            # 指定数据库连接地址</span><br><span class="line">            - name: spring.datasource.url</span><br><span class="line">              value: jdbc:mysql://mysql-service:3306/mall?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai</span><br><span class="line">            # 指定日志文件路径</span><br><span class="line">            - name: logging.path</span><br><span class="line">              value: /var/logs</span><br><span class="line">          volumeMounts:</span><br><span class="line">            - mountPath: /var/logs</span><br><span class="line">              name: log-volume</span><br><span class="line">      volumes:</span><br><span class="line">        - name: log-volume</span><br><span class="line">          hostPath:</span><br><span class="line">            path: /home/docker/mydata/app/mall-tiny-fabric/logs</span><br><span class="line">            type: DirectoryOrCreate</span><br></pre></td></tr></table></figure>

<ul>
<li>通过应用配置文件来创建Deployment；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl apply -f mall-tiny-fabric-deployment.yaml</span><br></pre></td></tr></table></figure>

<ul>
<li>我们可以通过<code>kubectl logs</code>命令来查看应用的启动日志；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[macro@linux-local k8s]$ kubectl get pods</span><br><span class="line">NAME                                           READY   STATUS    RESTARTS   AGE</span><br><span class="line">mall-tiny-fabric-deployment-8684857dff-pnz2t   1/1     Running   0          47s</span><br><span class="line">mysql-deployment-5dccc96ccf-sfxvg              1/1     Running   0          25m</span><br><span class="line">nginx-volume-deployment-6f6c89976d-nv2rn       1/1     Running   4          6d6h</span><br><span class="line">nginx-volume-deployment-6f6c89976d-tmhc5       1/1     Running   4          6d5h</span><br><span class="line">[macro@linux-local k8s]$ kubectl logs -f mall-tiny-fabric-deployment-8684857dff-pnz2t</span><br></pre></td></tr></table></figure>

<ul>
<li>如果想要从外部访问SpringBoot应用，需要创建Service，添加配置文件<code>mall-tiny-fabric-service.yaml</code>用于创建Service；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">apiVersion: v1</span><br><span class="line">kind: Service</span><br><span class="line">metadata:</span><br><span class="line">  name: mall-tiny-fabric-service</span><br><span class="line">spec:</span><br><span class="line">  type: NodePort</span><br><span class="line">  selector:</span><br><span class="line">    app: mall-tiny-fabric</span><br><span class="line">  ports:</span><br><span class="line">    - name: http</span><br><span class="line">      protocol: TCP</span><br><span class="line">      port: 8080</span><br><span class="line">      targetPort: 8080</span><br><span class="line">      # Node上的静态端口</span><br><span class="line">      nodePort: 30180</span><br></pre></td></tr></table></figure>

<ul>
<li>通过应用配置文件来创建Service；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl apply -f mall-tiny-fabric-service.yaml</span><br></pre></td></tr></table></figure>

<ul>
<li>此时服务已经暴露到了Node的<code>30180</code>端口上了；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[macro@linux-local k8s]$ kubectl get services</span><br><span class="line">NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE</span><br><span class="line">kubernetes                 ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          7d23h</span><br><span class="line">mall-tiny-fabric-service   NodePort    10.100.112.84    &lt;none&gt;        8080:30180/TCP   5s</span><br><span class="line">mysql-service              NodePort    10.107.189.51    &lt;none&gt;        3306:30306/TCP   13m</span><br><span class="line">nginx-service              NodePort    10.101.171.181   &lt;none&gt;        80:30080/TCP     6d2h</span><br></pre></td></tr></table></figure>

<ul>
<li>在Linux服务器上，我们可以通过<code>curl</code>命令来访问下项目的Swagger页面，不过只能查看到返回的一串HTML代码。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl $(minikube ip):30180/swagger-ui.html</span><br></pre></td></tr></table></figure>

<h3 id="外部访问应用"><a href="#外部访问应用" class="headerlink" title="#外部访问应用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E5%A4%96%E9%83%A8%E8%AE%BF%E9%97%AE%E5%BA%94%E7%94%A8">#</a>外部访问应用</h3><blockquote>
<p>由于使用Minikube安装的K8S Node处于Linux服务器的内网环境，无法直接从外部访问，所以我们需要安装一个Nginx反向代理下才能访问。</p>
</blockquote>
<ul>
<li><p>首先我们需要安装Nginx，对Nginx不熟悉的朋友直接参考该文章即可：<a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/9VZi2suAlomu1IRGy-qdCA">《Nginx的这些妙用，你肯定有不知道的！》open in new window</a></p>
</li>
<li><p>安装完成后添加一个Nginx的配置文件，这里我的配置路径为<code>/mydata/nginx/conf/conf.d/</code>，用于将<code>mall-tiny.macrozheng.com</code>域名的访问代理到K8S中的SpringBoot应用中去，<code>proxy_pass</code>为上面<code>curl</code>使用的路径；</p>
</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">    listen       80;</span><br><span class="line">    server_name  mall-tiny.macrozheng.com; #修改域名</span><br><span class="line"></span><br><span class="line">    location / &#123;</span><br><span class="line">        proxy_set_header Host $host:$server_port;</span><br><span class="line">        proxy_pass   http://192.168.49.2:30180; #修改为代理服务地址</span><br><span class="line">        index  index.html index.htm;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    error_page   500 502 503 504  /50x.html;</span><br><span class="line">    location = /50x.html &#123;</span><br><span class="line">        root   /usr/share/nginx/html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>重启Nginx服务，再修改访问Linux服务器的本机host文件，添加如下记录；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">192.168.5.94 mall-tiny.macrozheng.com</span><br></pre></td></tr></table></figure>

<ul>
<li>之后即可直接在本机上访问K8S上的SpringBoot应用了，访问地址：<a target="_blank" rel="noopener" href="http://mall-tiny.macrozheng.com/swagger-ui.html">http://mall-tiny.macrozheng.com/swagger-ui.html</a></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-03_10:44:42_68a847c397a973d1347e98681c40325e.png"></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="#总结"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E6%80%BB%E7%BB%93">#</a>总结</h2><p>通过把SpringBoot应用部署到K8S上的一顿操作，我们可以发现在K8S上部署和在Docker上部署有很多相似之处。K8S上很多部署用的脚本，直接翻译之前使用Docker Compose的脚本即可，非常类似。如果你之前用过Docker，那么你就可以轻松上手K8S！</p>
<h2 id="项目源码地址"><a href="#项目源码地址" class="headerlink" title="#项目源码地址"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/k8s/k8s_springboot.html#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80">#</a>项目源码地址</h2><p><a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-fabric">https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-fabric</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/c12cbbe61417.html">https://ko25891wan.gitlab.io/2024/01/c12cbbe61417.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/31d2f5f41a8c.html" title="一键部署 K8S 环境，10分钟玩转，这款开源神器实在太香了！"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">一键部署 K8S 环境，10分钟玩转，这款开源神器实在太香了！</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/159e9ef7ea80.html" title="再见 Docker ！5分钟转型 containerd !"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">再见 Docker ！5分钟转型 containerd !</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%A6%E5%89%8D%E5%87%86%E5%A4%87"><span class="toc-number">1.</span> <span class="toc-text">学前准备</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A8%E9%80%81%E9%95%9C%E5%83%8F%E5%88%B0Docker-Hub"><span class="toc-number">2.</span> <span class="toc-text">推送镜像到Docker Hub</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BA%94%E7%94%A8%E9%83%A8%E7%BD%B2"><span class="toc-number">3.</span> <span class="toc-text">应用部署</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%83%A8%E7%BD%B2MySQL"><span class="toc-number">3.1.</span> <span class="toc-text">部署MySQL</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%83%A8%E7%BD%B2SpringBoot%E5%BA%94%E7%94%A8"><span class="toc-number">3.2.</span> <span class="toc-text">部署SpringBoot应用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%96%E9%83%A8%E8%AE%BF%E9%97%AE%E5%BA%94%E7%94%A8"><span class="toc-number">3.3.</span> <span class="toc-text">外部访问应用</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80"><span class="toc-number">5.</span> <span class="toc-text">项目源码地址</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>